//package main

//import (
	//"github.com/gin-gonic/gin"
//)

//func main() {
	//r := gin.Default()
	//r.GET("/ping", func(c *gin.Context) {
		//c.JSON(200, gin.H{
			//"message": "pong",
		//})
	//})
	//r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
//}
package main

import (
    "database/sql"
    "fmt"
    "log"
    _ "github.com/go-sql-driver/mysql"
)

func main() {
    // DSN 格式：用户名:密码@tcp(地址:端口)/数据库名?charset=utf8mb4&parseTime=True&loc=Local
    dsn := "root:Lichuandi0911@tcp(localhost:3306)/lichaundi?charset=utf8mb4&parseTime=True&loc=Local"
    db, err := sql.Open("mysql", dsn)
    if err != nil {
        log.Fatal(err)
    }
    defer db.Close()
 
    // 检查数据库是否成功打开
    err = db.Ping()
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println("Successfully connected!")
	
	// 执行查询
rows, err := db.Query("SELECT id,user_name FROM tb_user")
if err != nil {
    log.Fatal(err)
}

 
for rows.Next() {
    var id int
    var name string
    if err := rows.Scan(&id, &name); err != nil {
        log.Fatal(err)
    }
    fmt.Printf("ID: %d, Name: %s\n", id, name)
}
defer rows.Close()
}

